﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using ProjectManagement.Models;
using Projectmanagement.Utl;
using Projectmanagement.Entity;

namespace Projectmanagement.Controllers
{
    public class MilestoneTemplateController : Controller
    {
        //
        // GET: /MilestoneTemplate/

        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _SelectIndex(int? conferenceid, int? projectid)
        {
            return View(new GridModel(DQ.GetMilestoneTemplate()));
        }
        [GridAction]
        public ActionResult _SelectIndexProject(int? conferenceid, int searchName)
        {
            var task = (from x in CH.DB.Tasks
                        //where x.ProjectID == conferenceid
                        select x).Distinct().ToList();
            if (searchName == 0)
            {
                //var milestone = DQ.GetMilestoneTemplate().Where(w => w.ID == searchName).ToList();
                return View(new GridModel(DQ.GetMilestoneTemplate().ToList()));
            }
            else
            {
                return View(new GridModel(DQ.GetMilestoneTemplate().Where(w => w.ID == searchName).ToList()));
               
            }
            //var exceptE = milestone.Where(a => !task.Select(b => b.MilestoneID).Contains(a.ID) || a.Projectid == conferenceid);

            //return View(new GridModel(milestone));
        }
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int? conferenceid)
        {
            var item = CH.GetDataByID<MilestoneTemplate>(id);
            if (TryUpdateModel(item))
            {
                CH.Edit<MilestoneTemplate>(item);
            }
            return View(new GridModel(DQ.GetMilestoneTemplate()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int? conferenceid)
        {
            var item = new MilestoneTemplate();

            if (TryUpdateModel(item))
            {
                CH.Create<MilestoneTemplate>(item);
            }
            return View(new GridModel(DQ.GetMilestoneTemplate()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? conferenceid)
        {
            CH.Delete<MilestoneTemplate>(id);
            return View(new GridModel(DQ.GetMilestoneTemplate()));
        }

    }
}
